import defaultSettings from '@/settings'

const {
  showSettings,
  fixedHeader,
  sidebarLogo
} = defaultSettings

const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  openTypeOptions: [{
      key: 'navigate',
      label: '保留当前页面'
    },
    {
      key: 'redirect',
      label: '关闭当前页面'
    },
    {
      key: 'switchTab',
      label: '跳转到底部导航页'
    },
    {
      key: 'outsite',
      label: '跳转到外部网页'
    }
  ],
  uploadConfig: localStorage.getItem('uploadConfig') ? JSON.parse(localStorage.getItem('uploadConfig')) : [],
}

const mutations = {
  CHANGE_SETTING: (state, {
    key,
    value
  }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  },
  // 上传配置
  SET_UPLOADCONFIG: (state, data) => {
    state.uploadConfig = data
    localStorage.setItem('uploadConfig', JSON.stringify(data))
  }
}

const actions = {
  changeSetting({
    commit
  }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
